﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CMTVision.Widgets.Modules
{
    //[System.Web.UI.ViewStateModeById]
    public partial class ThreeColumnsTemplate : CMTVision.Widgets.Impls.Template
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (Column1.ColumnHolder as IAttributeAccessor).SetAttribute("columnid", Column1.ID);
            (Column2.ColumnHolder as IAttributeAccessor).SetAttribute("columnid", Column2.ID);
            (Column3.ColumnHolder as IAttributeAccessor).SetAttribute("columnid", Column3.ID);
            (Column1.ColumnHolder as IAttributeAccessor).SetAttribute("class", Constants.UI_ColumnHolder_ClassName);
            (Column2.ColumnHolder as IAttributeAccessor).SetAttribute("class", Constants.UI_ColumnHolder_ClassName);
            (Column3.ColumnHolder as IAttributeAccessor).SetAttribute("class", Constants.UI_ColumnHolder_ClassName);
        }

        protected void RefreshButton_Click(object sender, EventArgs e)
        {
            ThreeColumnTemplateUpdatePanel.Update();
        }

        protected override void OnPreRender(EventArgs e)
        {
            var initDragDropScriptBuilder = new System.Text.StringBuilder();
            initDragDropScriptBuilder.Append("var pageId = 1;");
            initDragDropScriptBuilder.AppendFormat("widgetsManager.initialize(1, '.{0}', '.widgetHeader', 'widgetholder', '.refreshButton', '.newwidgetitem');", Constants.UI_ColumnHolder_ClassName);
            System.Web.UI.ScriptManager.RegisterStartupScript(ThreeColumnTemplateUpdatePanel, ThreeColumnTemplateUpdatePanel.GetType(), this.ClientID + "_InitDragDrop", initDragDropScriptBuilder.ToString(), true);
            base.OnPreRender(e);
        }
    }
}